/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package biofilter.records;

import biofilter.util.MappedPosition;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

import biofilter.util.*;
/**
 *
 * @author Daniel Quest
 * @date   Dec 25 2009
 */
public class HistogramRecordTest {

                              //     1        2        3        4        5        6        7
    private String    empty = "0.0 0.0\n0.0 0.0\n0.0 0.0\n0.0 0.0\n0.0 0.0\n0.0 0.0\n0.0 0.0\n";
    private String   stage1 = "0.0 0.0\n1.0 0.0\n1.0 0.0\n1.0 0.0\n0.0 0.0\n0.0 0.0\n0.0 0.0\n";
    private String   stage2 = "0.0 0.0\n1.0 0.0\n1.0 0.0\n1.0 0.0\n1.0 0.0\n1.0 0.0\n1.0 0.0\n";
    private String endpoint = "0.0 0.0\n1.0 0.0\n2.0 0.0\n2.0 0.0\n2.0 0.0\n1.0 0.0\n1.0 0.0\n";
    private String   nstage1 = "0.0 0.0\n0.0 1.0\n0.0 1.0\n0.0 1.0\n0.0 0.0\n0.0 0.0\n0.0 0.0\n";
    private String   nstage2 = "0.0 0.0\n0.0 1.0\n0.0 1.0\n0.0 1.0\n0.0 1.0\n0.0 1.0\n0.0 1.0\n";
    private String nendpoint = "0.0 0.0\n0.0 1.0\n0.0 2.0\n0.0 2.0\n0.0 2.0\n0.0 1.0\n0.0 1.0\n";
    //1234567
    // xxx
    //    xxx
    //  xxx
    //0122211
    SequencePosition sp1 = null;
    SequencePosition sp2 = null;
    SequencePosition sp3 = null;
    public HistogramRecordTest() {
        sp1 = new SequencePosition();
        sp2 = new SequencePosition();
        sp3 = new SequencePosition();
        sp1.set(2, 4, '+');
        sp1.setWeight(1.0);
        sp2.set(5, 7, '+');
        sp2.setWeight(1.0);
        sp3.set(3, 5, '+');
        sp3.setWeight(1.0);
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of set method, of class HistogramRecord.
     */
    @Test
    public void testSet() {
        System.out.println("set");
        HistogramRecord instance = new HistogramRecord();
        instance.set(empty);
        String s = instance.get();
        assertEquals(empty, s);
    }

    /**
     * Test of get method, of class HistogramRecord.
     */
    @Test
    public void testGet() {
        System.out.println("get");
        HistogramRecord instance = new HistogramRecord();
        instance.set(empty);
        String expResult = empty;
        String result = instance.get();
        assertEquals(expResult, result);
    }

    /**
     * Test of createRecord method, of class HistogramRecord.
     */
    @Test
    public void testCreateRecord_0args() {
        System.out.println("createRecord");
        HistogramRecord instance = new HistogramRecord();
        String expResult = empty;
        String result = instance.createRecord();
        assertEquals(expResult, result);
    }

    /**
     * Test of map method, of class HistogramRecord.
     */
    @Test
    public void testMap() {
        System.out.println("map");
        HistogramRecord instance = new HistogramRecord();
        assertEquals(empty, instance.get());
        instance.map(sp1);
        //System.err.println(instance.get());
        assertEquals(stage1, instance.get());
        instance.map(sp2);
        assertEquals(stage2, instance.get());
        instance.map(sp3);
        assertEquals(endpoint, instance.get());
    }

    /**
     * Test of map method, of class HistogramRecord.
     */
    @Test
    public void testNegMap() {
        System.out.println("negativeMap");
        SequencePosition nsp1 = new SequencePosition();
        SequencePosition nsp2 = new SequencePosition();
        SequencePosition nsp3 = new SequencePosition();
        nsp1.set(2, 4, '-');
        nsp1.setWeight(1.0);
        nsp2.set(5, 7, '-');
        nsp2.setWeight(1.0);
        nsp3.set(3, 5, '-');
        nsp3.setWeight(1.0);
        HistogramRecord instance = new HistogramRecord();
        assertEquals(empty, instance.get());
        instance.map(nsp1);
        //System.err.println(instance.get());
        assertEquals(nstage1, instance.get());
        instance.map(nsp2);
        assertEquals(nstage2, instance.get());
        instance.map(nsp3);
        assertEquals(nendpoint, instance.get());
    }


    /**
     * Test of addTarget method, of class HistogramRecord.
     */
    @Test
    public void testGetSetTarget() {
        System.out.println("getSetTarget");
        String id = "NC_000012345";  //some made up accession number
        HistogramRecord instance = new HistogramRecord();
        instance.setTarget(id);
        String target = instance.getTarget();
        assertEquals(target,id);
    }

    /**
     * Test of hasTarget method, of class HistogramRecord.
     */
    @Test
    public void testTargetMatches() {
        System.out.println("targetMatches");
        String id = "NC_00";
        HistogramRecord instance = new HistogramRecord();
        instance.setTarget("NC_000012345");
        boolean expResult = true;
        boolean result = instance.targetMatches(id);
        assertEquals(expResult, result);
        id = "NC_000012345";
        result = instance.targetMatches(id);
        assertEquals(expResult, result);
        
    }

}